import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

/// 添加flutter_test库
/// 执行 flutter test test/test_widget/findWidget.dart
void main() {
  testWidgets('find a Text Widget', (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      home: Scaffold(
        body: Text('H'),
      ),
    ));
    expect(find.text('H'), findsOneWidget);
  });

  testWidgets('find a Widget using a Key', (WidgetTester tester) async {
    final testKey = Key('K');
    await tester.pumpWidget(MaterialApp(
      key: testKey,
      home: Container(),
    ));
    expect(find.byKey(testKey), findsOneWidget);
  });

  testWidgets('find a specific instance', (WidgetTester tester) async {
    final childWidget = Padding(
      padding: EdgeInsets.zero,
    );
    await tester.pumpWidget(Container(
      child: childWidget,
    ));
    expect(find.byWidget(childWidget), findsOneWidget);
  });
}
